package java8.lambda.demo03;

import java8.lambda.demo01.Apple;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @author ChangLiang
 * @date 2020/4/22
 */
public class AppleConsumer {

    public static void consumeAppleWithFor(List<Apple> apples, Consumer<Apple> consumer) {
        for (Apple apple : apples) {
            consumer.accept(apple);
        }
    }

    public static void consumeAppleWithForeach(List<Apple> apples, Consumer<Apple> consumer) {
        apples.forEach((consumer::accept));
    }

    public static void consumeAppleWithBiConsumer(List<Apple> apples, BiConsumer<Apple, String> consumer, String str) {
        for (Apple apple : apples) {
            consumer.accept(apple,str);
        }
    }

    public static void consumeAppleWithBiConsumerForeach(List<Apple> apples, BiConsumer<Apple, String> consumer, String str) {
        apples.forEach((apple)->consumer.accept(apple,str));
    }
}
